﻿using System;
using System.Collections.Generic;
using System.Text;
using NHibernate;
using NHibernate.Expression;
using Castle.ActiveRecord;
using Castle.Components.Validator;
using System.ComponentModel;
using Castle.ActiveRecord.Queries;
namespace Mang24k99.Model.COMM
{
    [ActiveRecord(Table = "KT_COMM_TREECONDITION")]
    public partial class MKtCommTreecondition : ActiveRecordValidationBase
    {
        /// <summary>
        /// Deleteses the specified where.
        /// </summary>
        /// <param name="where">The where.</param>
        public static void Deletes(string where)
        {
            DeleteAll(typeof(MKtCommTreecondition), where);
        }
        /// <summary>
        /// Deleteses the specified pk values.
        /// </summary>
        /// <param name="pkValues">The pk values.</param>
        public static void Deletes(System.Collections.IEnumerable pkValues)
        {
            DeleteAll(typeof(MKtCommTreecondition), pkValues);
        }

        /// <summary>
        /// Selects all.
        /// </summary>
        /// <returns></returns>
        public static IList<MKtCommTreecondition> SelectAll()
        {
            return (IList<MKtCommTreecondition>)FindAll(typeof(MKtCommTreecondition));
        }
        /// <summary>
        /// Selects all.
        /// </summary>
        /// <param name="criteria">The criteria.</param>
        /// <returns></returns>
        public static IList<MKtCommTreecondition> SelectAll(params ICriterion[] criteria)
        {
            return (IList<MKtCommTreecondition>)FindAll(typeof(MKtCommTreecondition), criteria);
        }
        /// <summary>
        /// Selects all.
        /// </summary>
        /// <param name="orders">The orders.</param>
        /// <param name="criteria">The criteria.</param>
        /// <returns></returns>
        public static IList<MKtCommTreecondition> SelectAll(Order[] orders, params ICriterion[] criteria)
        {
            return (IList<MKtCommTreecondition>)FindAll(typeof(MKtCommTreecondition), orders, criteria);
        }
        /// <summary>
        /// Selects all.
        /// </summary>
        /// <param name="detachedCriteria">The detached criteria.</param>
        /// <param name="orders">The orders.</param>
        /// <returns></returns>
        public static IList<MKtCommTreecondition> SelectAll(DetachedCriteria detachedCriteria, params Order[] orders)
        {
            return (IList<MKtCommTreecondition>)FindAll(typeof(MKtCommTreecondition), detachedCriteria, orders);
        }


        /// <summary>
        /// Selects all query.
        /// </summary>
        /// <param name="query">The query.</param>
        /// <returns></returns>
        [DataObjectMethod(DataObjectMethodType.Select)]
        public static IList<MKtCommTreecondition> SelectAllQuery(SimpleQuery query)
        {
            return (IList<MKtCommTreecondition>)ExecuteQuery(query);
        }


        /// <summary>
        /// Selects the by primary key.
        /// </summary>
        /// <param name="ID">The ID.</param>
        /// <returns></returns>
        public static MKtCommTreecondition SelectByPrimaryKey(object ID)
        {
            return (MKtCommTreecondition)FindByPrimaryKey(typeof(MKtCommTreecondition), ID, false);
        }

        /// <summary>
        /// Selects the by primary key.
        /// </summary>
        /// <param name="ID">The ID.</param>
        /// <returns></returns>
        public static MKtCommTreecondition SelectOne(DetachedCriteria detachedCriteria)
        {
            return (MKtCommTreecondition)FindOne(typeof(MKtCommTreecondition), detachedCriteria);
        }
        /// <summary>
        /// Selects the one.
        /// </summary>
        /// <param name="criteria">The criteria.</param>
        /// <returns></returns>
        public static MKtCommTreecondition SelectOne(params ICriterion[] criteria)
        {
            return (MKtCommTreecondition)FindOne(typeof(MKtCommTreecondition), criteria);
        }

        /// <summary>
        /// Selects the first.
        /// </summary>
        /// <param name="criteria">The criteria.</param>
        /// <returns></returns>
        public static MKtCommTreecondition SelectFirst(params ICriterion[] criteria)
        {
            return (MKtCommTreecondition)FindFirst(typeof(MKtCommTreecondition), criteria);
        }
        /// <summary>
        /// Selects the first.
        /// </summary>
        /// <param name="orders">The orders.</param>
        /// <param name="criteria">The criteria.</param>
        /// <returns></returns>
        public static MKtCommTreecondition SelectFirst(Order[] orders, params ICriterion[] criteria)
        {
            return (MKtCommTreecondition)FindFirst(typeof(MKtCommTreecondition), orders, criteria);
        }
        /// <summary>
        /// Selects the first.
        /// </summary>
        /// <param name="detachedCriteria">The detached criteria.</param>
        /// <param name="orders">The orders.</param>
        /// <returns></returns>
        public static MKtCommTreecondition SelectFirst(DetachedCriteria detachedCriteria, Order[] orders)
        {
            return (MKtCommTreecondition)FindFirst(typeof(MKtCommTreecondition), detachedCriteria, orders);

        }

        /// <summary>
        /// Selects the ALL by property.
        /// </summary>
        /// <param name="property">The property.</param>
        /// <param name="value">The value.</param>
        /// <returns></returns>
        public static IList<MKtCommTreecondition> SelectALLByProperty(string property, object value)
        {
            return (IList<MKtCommTreecondition>)FindAllByProperty(typeof(MKtCommTreecondition), property, value);
        }
        /// <summary>
        /// Selects the ALL by property.
        /// </summary>
        /// <param name="orderByColumn">The order by column.</param>
        /// <param name="property">The property.</param>
        /// <param name="value">The value.</param>
        /// <returns></returns>
        public static IList<MKtCommTreecondition> SelectALLByProperty(string orderByColumn, string property, object value)
        {
            return (IList<MKtCommTreecondition>)FindAllByProperty(typeof(MKtCommTreecondition), orderByColumn, property, value);
        }

        /// <summary>
        /// Selects the ALL sliced.
        /// </summary>
        /// <param name="firstResult">The first result.</param>
        /// <param name="maxResult">The max result.</param>
        /// <param name="detachedCriteria">The detached criteria.</param>
        /// <returns></returns>
        public static IList<MKtCommTreecondition> SelectALLSliced(int firstResult, int maxResult, DetachedCriteria detachedCriteria)
        {
            return (IList<MKtCommTreecondition>)SlicedFindAll(typeof(MKtCommTreecondition), firstResult, maxResult, detachedCriteria);
        }
        /// <summary>
        /// Selects the ALL sliced.
        /// </summary>
        /// <param name="firstResult">The first result.</param>
        /// <param name="maxResult">The max result.</param>
        /// <param name="criteria">The criteria.</param>
        /// <returns></returns>
        public static IList<MKtCommTreecondition> SelectALLSliced(int firstResult, int maxResult, params ICriterion[] criteria)
        {
            return (IList<MKtCommTreecondition>)SlicedFindAll(typeof(MKtCommTreecondition), firstResult, maxResult, criteria);
        }
        /// <summary>
        /// Selects the ALL sliced.
        /// </summary>
        /// <param name="firstResult">The first result.</param>
        /// <param name="maxResult">The max result.</param>
        /// <param name="orders">The orders.</param>
        /// <param name="detachedCriteria">The detached criteria.</param>
        /// <returns></returns>
        public static IList<MKtCommTreecondition> SelectALLSliced(int firstResult, int maxResult, Order[] orders, DetachedCriteria detachedCriteria)
        {
            return (IList<MKtCommTreecondition>)SlicedFindAll(typeof(MKtCommTreecondition), firstResult, maxResult, orders, detachedCriteria);
        }
        /// <summary>
        /// Selects the ALL sliced.
        /// </summary>
        /// <param name="firstResult">The first result.</param>
        /// <param name="maxResult">The max result.</param>
        /// <param name="orders">The orders.</param>
        /// <param name="criteria">The criteria.</param>
        /// <returns></returns>
        public static IList<MKtCommTreecondition> SelectALLSliced(int firstResult, int maxResult, Order[] orders, params ICriterion[] criteria)
        {
            return (IList<MKtCommTreecondition>)SlicedFindAll(typeof(MKtCommTreecondition), firstResult, maxResult, orders, criteria);
        }

        /// <summary>
        /// Countses this instance.
        /// </summary>
        /// <returns></returns>
        public static int Counts()
        {
            return Count(typeof(MKtCommTreecondition));
        }
        /// <summary>
        /// Countses the specified detached criteria.
        /// </summary>
        /// <param name="detachedCriteria">The detached criteria.</param>
        /// <returns></returns>
        public static int Counts(DetachedCriteria detachedCriteria)
        {
            return Count(typeof(MKtCommTreecondition), detachedCriteria);
        }
        /// <summary>
        /// Countses the specified criteria.
        /// </summary>
        /// <param name="criteria">The criteria.</param>
        /// <returns></returns>
        public static int Counts(params ICriterion[] criteria)
        {
            return Count(typeof(MKtCommTreecondition), criteria);
        }


        /// <summary>
        /// Exists the specified id.
        /// </summary>
        /// <param name="id">The id.</param>
        /// <returns></returns>
        public static bool Exist(object id)
        {
            return Exists(typeof(MKtCommTreecondition), id);
        }
        /// <summary>
        /// Exists the specified id.
        /// </summary>
        /// <param name="id">The id.</param>
        /// <param name="detachedCriteria">The detached criteria.</param>
        /// <returns></returns>
        public static bool Exist(DetachedCriteria detachedCriteria)
        {
            return Exists(typeof(MKtCommTreecondition), detachedCriteria);
        }
        /// <summary>
        /// Exists the specified id.
        /// </summary>
        /// <param name="id">The id.</param>
        /// <param name="criteria">The criteria.</param>
        /// <returns></returns>
        public static bool Exist(params ICriterion[] criteria)
        {
            return Exists(typeof(MKtCommTreecondition), criteria);
        }
        protected override void OnDelete()
        {
            DeleteTime = DateTime.Now;
            MKtCommTreeconditionHistory mHistory = new MKtCommTreeconditionHistory();
            Common.ModelCommon.CopyObjectValues(this, mHistory);
            mHistory.TreeNO = MKtCommTreeconfig.TreeNO;
            mHistory.Create();
            base.OnDelete();
        }

        /// <summary>
        /// 取得最大编号
        /// </summary>
        /// <returns></returns>
        public static int GetMaxNO()
        {
            MKtCommTreecondition conditon = new MKtCommTreecondition();
            string Hql = @"select max(conditon.CondNO) from MKtCommTreecondition conditon  ";
            string count = @"select count(conditon.CondNO) from MKtCommTreecondition conditon ";
            ScalarQuery querycount = new ScalarQuery(typeof(MKtCommTreecondition), count);
            if (Convert.ToInt32(ExecuteQuery(querycount)) == 0)
            {
                return 0;
            }
            ScalarQuery query = new ScalarQuery(typeof(MKtCommTreecondition), Hql);
            return (int)ExecuteQuery(query);
        }

        /// <summary>
        /// 通过where语句查询记录
        /// </summary>
        /// <param name="where"></param>
        /// <returns></returns>
        public static IList<MKtCommTreecondition> SelectByWhere(string where)
        {
            string hql = "from MKtCommTreecondition condition " + where;
            SimpleQuery query = new SimpleQuery(typeof(MKtCommTreecondition), hql);
            return (IList<MKtCommTreecondition>)ExecuteQuery(query);
        }


        [BelongsTo("TREE_NO", Cascade = CascadeEnum.None)]
        public MKtCommTreeconfig MKtCommTreeconfig
        {
            get
            {
                return _MKtCommTreeconfig;
            }
            set
            {
                _MKtCommTreeconfig = value;
            }
        }


        /// <summary>
        /// Gets or sets the CondNO.(条件编号)
        /// </summary>
        /// <value>The CondNO.</value>
        /// <remarks>
        /// 条件编号
        /// </remarks>
        [PrimaryKey(PrimaryKeyType.Assigned, "COND_NO"),
        ValidateIsUnique("条件编号必须唯一", RunWhen = RunWhen.Insert),
        ValidateRange(0, 2147483647, "条件编号的值要在0到2147483647之间"),
        ]
        public int? CondNO
        {
            get
            {
                return _CondNO;
            }
            set
            {
                _CondNO = value;
            }
        }


        /// <summary>
        /// Gets or sets the ID.(ID)
        /// </summary>
        /// <value>The ID.</value>
        /// <remarks>
        /// ID
        /// </remarks>
        [Property("ID", Insert = false, Update = false),
        ValidateRange(0, 2147483647, "ID的值要在0到2147483647之间"),
        ]
        public int? ID
        {
            get
            {
                return _ID;
            }
            set
            {
                _ID = value;
            }
        }


        /// <summary>
        /// Gets or sets the FieldName.(表字段名称)
        /// </summary>
        /// <value>The FieldName.</value>
        /// <remarks>
        /// 表字段名称
        /// </remarks>
        [Property("FIELD_NAME"),
        ValidateLength(1, 30, "表字段名称长度必须在1到30之间"),
        ]
        public string FieldName
        {
            get
            {
                return _FieldName;
            }
            set
            {
                _FieldName = value;
            }
        }


        /// <summary>
        /// Gets or sets the FieldValue.(条件值)
        /// </summary>
        /// <value>The FieldValue.</value>
        /// <remarks>
        /// 条件值
        /// </remarks>
        [Property("FIELD_VALUE"),
        ValidateLength(1, 60, "条件值长度必须在1到60之间"),
        ]
        public string FieldValue
        {
            get
            {
                return _FieldValue;
            }
            set
            {
                _FieldValue = value;
            }
        }


        /// <summary>
        /// Gets or sets the CondType.(条件类型)
        /// </summary>
        /// <value>The CondType.</value>
        /// <remarks>
        /// 条件类型
        /// </remarks>
        [Property("COND_TYPE"),
        ValidateRange(0, 2147483647, "条件类型的值要在0到2147483647之间"),
        ]
        public int? CondType
        {
            get
            {
                return _CondType;
            }
            set
            {
                _CondType = value;
            }
        }


        /// <summary>
        /// Gets or sets the IsValidate.(是否有效)
        /// </summary>
        /// <value>The IsValidate.</value>
        /// <remarks>
        /// 是否有效
        /// </remarks>
        [Property("IS_VALIDATE"),
        ValidateRange(0, 2147483647, "是否有效的值要在0到2147483647之间"),
        ]
        public int? IsValidate
        {
            get
            {
                return _IsValidate;
            }
            set
            {
                _IsValidate = value;
            }
        }


        /// <summary>
        /// Gets or sets the InputTime.(输入时间)
        /// </summary>
        /// <value>The InputTime.</value>
        /// <remarks>
        /// 输入时间
        /// </remarks>
        [Property("INPUT_TIME"),
        ]
        public DateTime? InputTime
        {
            get
            {
                return _InputTime;
            }
            set
            {
                _InputTime = value;
            }
        }


        /// <summary>
        /// Gets or sets the ModifyTime.(修改时间)
        /// </summary>
        /// <value>The ModifyTime.</value>
        /// <remarks>
        /// 修改时间
        /// </remarks>
        [Property("MODIFY_TIME"),
        ]
        public DateTime? ModifyTime
        {
            get
            {
                return _ModifyTime;
            }
            set
            {
                _ModifyTime = value;
            }
        }


        /// <summary>
        /// Gets or sets the DeleteTime.(删除时间)
        /// </summary>
        /// <value>The DeleteTime.</value>
        /// <remarks>
        /// 删除时间
        /// </remarks>
        [Property("DELETE_TIME"),
        ]
        public DateTime? DeleteTime
        {
            get
            {
                return _DeleteTime;
            }
            set
            {
                _DeleteTime = value;
            }
        }



        private int? _CondNO;

        private int? _ID;

        private MKtCommTreeconfig _MKtCommTreeconfig;
        private string _FieldName;

        private string _FieldValue;

        private int? _CondType;

        private int? _IsValidate;

        private DateTime? _InputTime;

        private DateTime? _ModifyTime;

        private DateTime? _DeleteTime;


    }
}
